package com.neiquan.secondhand.interceptor;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * 
 * @author wangz
 * <br/>
 * 系统级拦截器,包括授权、URL重定向、客户端信息...
 *
 */
public class SystemInterceptor implements HandlerInterceptor {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		
//		HttpSession session = request.getSession();
//		Map map = (Map) session.getAttribute("sysUserPO");
//		if(null == map) {
//			//System.out.println(request.getContextPath());
//			response.sendRedirect("/diving-back/api/sysUser/loginView.do");
//			//request.getRequestDispatcher("/diving-back/api/sysUser/loginView.do").forward(request, response);
//			return false;
//		}
		return true;
//		String requestType = response.getHeader("X-Requested-With");
//		if("XMLHttpRequest".equals(requestType)) {
//			response.setHeader("sessionstatus", "timeout");
//			return false;
//		}else {
//			response.sendRedirect("/diving-back/api/sysUser/loginView.do");
//	    	return false;
//		}
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		// TODO Auto-generated method stub

	}

}
